//
//  tableHeaderView.m
//  Demo
//
//  Created by colawh on 2019/3/13.
//  Copyright © 2019年 colawhdfws. All rights reserved.
//

#import "tableHeaderView.h"
#import "BsCollectionView.h"
#import "DemoHelp.h"
#import <Masonry/Masonry.h>

@interface tableHeaderView ()

@property (nonatomic,strong) UIImageView *videoView;

@property (nonatomic,strong) UIView *contentView;

@property (nonatomic,strong) UILabel *titleLb;

@property (nonatomic,strong) UILabel *perTitleLb;

@property (nonatomic,strong) UILabel *infoLb;



@end

@implementation tableHeaderView

- (instancetype)init{
    if ([super init]) {
        [self configUI];
    }
    return self;
}

- (void)configUI{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.videoView];
    [self addSubview:self.contentView];
    [self.contentView addSubview:self.titleLb];
    [self.contentView addSubview:self.perTitleLb];
    [self.contentView addSubview:self.infoLb];
    [self.contentView addSubview:self.headCollectionView];

}
- (void)configureHeaderViewArray:(NSArray *)array{
    _videoView.backgroundColor = [UIColor purpleColor];
    _titleLb.text = self.course_title;
    _perTitleLb.text = self.course_description;
    _infoLb.text = self.indicatorStr;
    _contentView.backgroundColor = [UIColor whiteColor];
    CGFloat titleHeight = [DemoHelp getLB:_titleLb HeightByWidth:(kUIScreenWidth - 30)]>30*2?36*2:[DemoHelp getLB:_titleLb HeightByWidth:(kUIScreenWidth - 30)];
    
    [_titleLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(titleHeight));
    }];
    self.headCollectionView.dataSource = [array mutableCopy];
    [self layoutIfNeeded];

}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGFloat videoRote = 0.4;
    CGFloat gap = 15;
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kUIScreenWidth);
        make.bottom.greaterThanOrEqualTo(self->_contentView.mas_bottom).offset(3);
    }];

    [_videoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self);
        make.height.mas_equalTo(kUIScreenWidth*videoRote);
    }];
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_videoView.mas_bottom);
        make.bottom.left.right.equalTo(self);
    }];
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_contentView).offset(gap);
        make.left.equalTo(self->_contentView).offset(gap);
        make.right.equalTo(self->_contentView).offset(-gap);
//        make.height.lessThanOrEqualTo(@(34*2));
    }];

    [_perTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_titleLb.mas_bottom).offset(gap);
        make.right.equalTo(@[self->_titleLb,self->_infoLb]);
        make.left.equalTo(@[self->_titleLb,self->_infoLb]);
    }];

    [_infoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_perTitleLb.mas_bottom).offset(gap);
        make.height.equalTo(@16);
//        make.bottom.equalTo(self).offset(-gap);
    }];
    [_headCollectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_infoLb.mas_bottom);
        make.left.equalTo(self);
        make.bottom.lessThanOrEqualTo(self->_contentView.mas_bottom).offset(-gap);
        make.size.mas_equalTo(CGSizeMake(kUIScreenWidth, [self->_headCollectionView realHeight]));
    }];
    
}
- (UIImageView *)videoView{
    if (!_videoView) {
        _videoView = [UIImageView new];
    }
    return _videoView;
}
- (UIView *)contentView{
    if (!_contentView) {
        _contentView = [UIView new];
    }
    return _contentView;
}
- (UILabel *)titleLb{
    if (!_titleLb) {
        _titleLb = [DemoHelp getLbByFont:18];
        _titleLb.numberOfLines = 2;
        _titleLb.textColor = kUIColorFromRGB(0x091522);
    }
    return _titleLb;
}

- (UILabel *)perTitleLb{
    if (!_perTitleLb) {
        _perTitleLb = [DemoHelp getLbByFont:14];
        [DemoHelp setLbHuggingAndCompress:_perTitleLb];
        _perTitleLb.numberOfLines = 0;
        _perTitleLb.textColor = kUIColorFromRGBA(0x091522, 0.95);
    }
    return _perTitleLb;
}
- (UILabel *)infoLb{
    if (!_infoLb) {
        _infoLb = [DemoHelp getLbByFont:12];
        _infoLb.textColor = kUIColorFromRGBA(0x091522, 0.7);
    }
    return _infoLb;
}
- (BsCollectionView *)headCollectionView{
    if (!_headCollectionView) {
        _headCollectionView = [[BsCollectionView alloc]initWithItemArray:@[@"高级酒店管理",@"酒店前台",@"酒店新人超级前台课程",@"酒店新手",@"酒店打工哈根数据啊工商局和按时开酒吧肯定会给"]];
    }
    return _headCollectionView;
}
@end
